package com.chenqi.library.recycleview.drag

import android.support.v7.widget.RecyclerView
import android.support.v7.widget.helper.ItemTouchHelper
import com.chenqi.library.recycleview.base.ItemTouchCallBack

/**
 * 作者: CQ
 * 日期: 2021-03-22
 * 说明:设置滑动和拖拽
 */
class DragRecycleViewUtils {
    companion object {
        /**
         * isDrag 是否支持拖拽
         * isSwipe 是否支持侧滑
         */
        fun <T> onAddDraRecycleView(recyclerView: RecyclerView, adapter: DragRecycleViewAdapter<T>, isDrag: Boolean, isSwipe: Boolean) {
            val touchCallBack = ItemTouchCallBack()
            touchCallBack.setOnItemTouchListener(adapter)
            val itemTouchHelper = ItemTouchHelper(touchCallBack)
            touchCallBack.isDrag = isDrag
            touchCallBack.isSwipe = isSwipe
            itemTouchHelper.attachToRecyclerView(recyclerView)
        }
    }
}

